<!DOCTYPE html>
<html>
	<head>
		<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
		<meta content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport" />
		<meta content="telephone=no" name="format-detection" />
		<meta content="address=no" name="format-detection" />
		<meta name="apple-mobile-web-app-capable" content="no" />
		<link rel="apple-touch-icon-precomposed" href="http://img0.zz91.com/zz91/images/logo.png" />
		<link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-precomposed" />
		<meta name="apple-touch-fullscreen" content="YES">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="shortcut icon" href="http://img0.zz91.com/front/favicon.ico" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="http://b.zz91.com/layui/css/layui.css"/>
		<script type="text/javascript" src="http://b.zz91.com/layui/layui.js"></script>
		<!--[if lt IE 9]>
		  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
		  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
		<![endif]--> 
		<style>
			.mainbox{
				margin: 10px;
			}
			.dingjiabox{
				width: 500px;
				margin: 20px;
			}
			.grid-demo{
				padding: 20px; 
				text-align: center;
				background-color: #79C48C; 
				color: #fff;
				margin: 20px 0 10px;
			}
			.grid-demo span{
				font-size: 18px;
				font-weight: bold;
			}
			.grid-demo-bg1{
				background-color: #fb7885;
			}
			.grid-demo-bg2{
				background-color: #02a9f3;
			}
			.grid-demo-bg3{
				background-color: #9774cf;
			}
			.layui-input-block{
				line-height: 38px;
				border-bottom: solid 1px #ccc;
			}
			#price{
				background-color: #FFB800;
			}
		</style>
		<script>
		function selectoption(id,value){
			$("#"+id).val(value);
		}</script>
	</head>
	<body>
		<div class="mainbox">
			<div class="demoTable">
				<div class=" layui-form">
					
				  	<div class="layui-inline">
				  		<div class="layui-input-inline">
					    	<select name="suppliers_selfid" id="suppliers_selfid">
					          	<option value="">选择供应商</option>
					          	{%for list in supplier_list%}
					          	<option value={{list.selfid}}>{{list.name}}</option>
					          	{%endfor%}
					        </select>
				        </div>
				  	</div>
				  	
				    <div class="layui-inline layui-form-item" style="margin-bottom: 0;">
				    	<label class="layui-form-label" style="width: 30px;">时间</label>
				      	<div class="layui-input-inline" style="width: 100px;">
				        	<input type="text" name="time_min" id="time_min" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
				     	</div>
				      	<div class="layui-form-mid">至</div>
				      	<div class="layui-input-inline" style="width: 100px;">
				        	<input type="text" name="time_max" id="time_max" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
				      	</div>
				    </div>
				    
				    
				    <div class="layui-inline">
				  		<div class="layui-input-inline">
					    	<select name="products_selfid" id="products_selfid">
					          	<option value="">产品</option>
					          	{%for list in productslist%}
					          	<option value="{{list.selfid}}">{{list.name}}</option>
					          	{%endfor%}
					        </select>
				        </div>
				  	</div>
				  	
			  		<button class="layui-btn layui-btn-normal" data-type="reload">搜索</button>
				</div>
			</div>
			
			 
			<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table> 
		</div>
		<form class="layui-form pricebox" action="storage_save.html" method="post" lay-filter="dingjiabox">
		<div class="pop-dingjia dingjiabox" style="display:none">
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>供应商</label>
				<div class="layui-input-block supplier_name">
					
				</div>
			</div>
			<div class="layui-form-item">
		    	<label class="layui-form-label"><span style="color: red;">*</span>产品类别</label>
		    	<div class="layui-input-inline" >
		    		<select name="products_selfid_now" id="products_selfid_now"  class="db-select products_selfid_now" lay-verify="required">
						<option value=''>请选择产品</option>
						{%for list in productslist%}
						<option value='{{list.selfid}}'>{{list.name}}</option>
						{%endfor%}
					</select>
		    	</div>
		  	</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>毛重</label>
				<div class="layui-input-block gw">
					
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>皮重</label>
				<div class="layui-input-block tare">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>净重</label>
				<div class="layui-input-block nw">
				</div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label"></label>
			    <div class="layui-input-inline iszerotare" >
			    	<input type="checkbox" name="tare_check" lay-filter="tare_check" id="tare_check" value="1"/><label forid=tare_check>是否0皮重</label>
			    </div>
			  </div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>单价</label>
				<div class="layui-input-inline">
					<input type="number" name="price" id="price" lay-verify="required" placeholder="请输入单价" autocomplete="off" class="layui-input"> 
				</div>
				元/kg
			</div>
		</div>
		</form>
	</body>
	
	<script id="barcaozuo" type="text/html">
		  <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">作废</a>
	</script>
	<script src="js/jquery.js" charset="utf-8"></script>
	<script src="js/comm.js" charset="utf-8"></script>
	<script>
		layui.use(['table','laydate','form'], function(){
		  var table = layui.table;
		  var form= layui.form;
		  var $ = layui.$;
		  var laydate = layui.laydate;
		  var tare_check=0;
		  var maxid='1970-1-1';
		  //日期
			laydate.render({
				elem: '#time_min'
			});
			laydate.render({
				elem: '#time_max'
			});
			
		  //方法级渲染
		  function tablerender(){table.render({
		    elem: '#LAY_table_user'
		    ,url: 'pricing_data.html?suppliers_selfid='+$('#suppliers_selfid').val()+'&products_selfid='+$('#products_selfid').val()+'&time_min='+$('#time_min').val()+'&time_max='+$('#time_max').val()
		    ,cols: [[
		      {field:'code', title: '单号', width:120}
		      ,{field:'supplier_name', title: '供应商', width:150}
		      ,{field:'product_name', title: '品名', width:120}
		      ,{field:'price_text', title: '单价（元/kg）', width:120,event: 'setprice', style:'cursor: pointer;'}
		      ,{field:'gw', title: '毛重（kg）', width:100}
		      ,{field:'tare', title: '皮重（kg）', width:120}
		      ,{field:'nw', title: '净重（kg）', width:100}
		      ,{field:'total', title: '总价（元）', width:120,style:'background-color: #009688; color: #fff;font-size:20px'}
		      ,{field:'gmt_created', title: '过磅时间', width:170}
		      ,{field:'caozuo', title: '操作', width:100,toolbar:"#barcaozuo"}
		    ]]
		    ,id: 'testReload'
		    ,page: true
		    ,limit: 10
		    ,limits:[]
		    ,height: 'full-80'
		    ,even: true
		  })};
		  tablerender();

		  $('.demoTable .layui-btn').on('click', function(){
		  	tablerender();
		  });
		  //监听单元格事件
		  table.on('tool(user)', function(obj){
		    var data = obj.data;
		    if(obj.event === 'setprice'){
		    	$(".supplier_name").html(data.supplier_name);
		    	$(".gw").html(data.gw+" kg");
		    	$(".nw").html(data.nw+" kg");
		    	$(".tare").html(data.tare+" kg");
		    	$("#price").val(data.price);
		    	//alert(data.tare_check);
		    	
		    	$("#products_selfid_now").val(data.products_selfid);
		    	$("[name = tare_check]:checkbox").attr("checked", false);
		    	//form.render("select","dingjiabox");
		    	//form.render("radio","dingjiabox");
		    	
		        layer.open({
					area: ['500px,600px'],
					title: false,
				  	type: 1,
				  	skin: 'layui-layer-demo', //样式类名
				  	closeBtn: 1, //不显示关闭按钮
				  	anim: 2,
				  	shadeClose: false, //开启遮罩关闭
				  	content: $(".pop-dingjia"),
				  	btn: ['确定','取消'],
				  	btnAlign:"c",
				  	yes: function(){
				  		var products_selfid=$(".products_selfid_now").val();
				  		if (products_selfid==""){
				  			alert("请选择产品类别！");
				  			return false
				  		}
				  		if ($(".price").val()==""){
				  			alert("请输入价格！");
				  			return false
				  		}
				  		ret={
				  			"id":data.id,
				  			"products_selfid":products_selfid,
				  			"price":$("#price").val(),
				  			"tare_check":tare_check
				  		}
				  		crmajax('post','pricing_save.html',ret,function(){
				  			tablerender();
				  			layer.closeAll();
				  		},function(){});
			        }
				});
				form.render();
				$("#price").focus();
		    }
		    if(obj.event === 'del'){
		    	layer.confirm('真的删除行么', function(index){
			        data={id:data.id};
			        //alert(data.id)
			        crmajax('post','storage_del.html',data,function(){obj.del();},function(){});
			        layer.close(index);
			        //tablerender();
			      });
		    }
		    
		  });
			form.on('checkbox(tare_check)', function(data){
				if (data.elem.checked==true){
					tare_check=1
				}else{
					tare_check=0
				}
			});
			function ajaxinfo(){
				var data={
					maxid:maxid
				}
				crmajax('post','pricing_add.html',data,function(ret){
					if (ret.err=='false'){
						tablerender();
						maxid=ret.time;
					}
				},function(){});
			}
			setInterval(ajaxinfo,3000);
		});
		$(".close-pop").on("click",function(){
			layer.closeAll();
		})
		
		
	</script>
</html>
